home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Tools / ckchan / qcheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  3.8 KB  |  191 lines

  1. /* qcheck.c: stand alone checker of q */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Tools/ckchan/RCS/qcheck.c,v 6.0 1991/12/18 20:28:55 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Tools/ckchan/RCS/qcheck.c,v 6.0 1991/12/18 20:28:55 jpo Rel $
  9.  *
  10.  * $Log: qcheck.c,v $
  11.  * Revision 6.0  1991/12/18  20:28:55  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "util.h"
  19. #include <isode/usr.dirent.h>
  20. #include "q.h"
  21. #include "retcode.h"
  22. #include "prm.h"
  23.  
  24.  
  25. static int QPrint();
  26. static int RecipPrint();
  27. static LIST_RCHAN *getnthchannel();
  28. static char     **get_all_messages();
  29.  
  30. main (argc, argv)
  31. int     argc;
  32. char    **argv;
  33. {
  34.     char    **all_msgs;
  35.     if (argc < 2) {
  36.         printf("usage : %s [all | msg.XXXX ...]\n",argv[0]);
  37.         exit(1);
  38.     }
  39.     sys_init(argv[0]);
  40.     argv++;
  41.  
  42.     if (strcmp(*argv,"all") == 0) {
  43.         /* get all messages in addr, directory */
  44.         all_msgs = get_all_messages();
  45.         qcheck(all_msgs);
  46.     } else
  47.         qcheck(argv);
  48. }
  49.  
  50. int     isMsg(entry)
  51. struct dirent   *entry;
  52. {
  53.     if (strncmp(entry->d_name,"msg.",4) == 0)
  54.         return 1;
  55.     else 
  56.         return 0;
  57. }
  58.  
  59. static char     **get_all_messages()
  60. {
  61.     int             num,
  62.             i = 0;
  63.     struct dirent   **namelist = NULL,
  64.             **ix;
  65.     char            **ret;
  66.     extern char     *quedfldir;
  67.  
  68.     num = _scandir(quedfldir, &namelist, isMsg, NULL);
  69.  
  70.     ret = (char **) calloc((num+1), sizeof(char *));
  71.     ix = namelist;
  72.     while ((i < num) && (*ix != 0)) {
  73.         ret[i++] = (*ix)->d_name;
  74.         ix++;
  75.     }
  76.  
  77.     if (namelist) free((char *) namelist);
  78.  
  79.     return ret;
  80. }
  81.  
  82.  
  83. qcheck(argv)
  84. char **argv;
  85. {
  86.     char            *file = NULL;
  87.     struct prm_vars prm;
  88.     Q_struct        que;
  89.     ADDR            *sender = NULL;
  90.     ADDR            *recips = NULL;
  91.     ADDR    *ix;
  92.     int             rcount;
  93.  
  94.     prm_init (&prm);
  95.     q_init (&que);
  96.     qinit (&que);
  97.  
  98.  
  99.     while ((file = *argv++) != NULLCP) {
  100.         sender = NULL;
  101.         recips = NULL;
  102.         prm_init (&prm);
  103.         q_init (&que);
  104.         if (rp_isbad(rd_msg(file,&prm,&que,&sender,&recips,&rcount))) {
  105.             rd_end();
  106.             printf("Bad message %s : rd_msg fails\n",file);
  107.         } else {
  108.             rd_end();
  109.             QPrint(file,&que,sender);
  110.             ix = recips;
  111.             while (ix != NULL) {
  112.                 RecipPrint(ix);
  113.                 ix = ix->ad_next;
  114.             }
  115.             printf("***** End of Message *****\n\n");
  116.  
  117.         }
  118.         q_free (&que);
  119.     }
  120. }
  121.  
  122.  
  123. static int QPrint(file, que,sender)
  124. char            *file;
  125. Q_struct        *que;
  126. ADDR            *sender;
  127. {
  128.     printf("***** Message %s *****\n",file);
  129.     printf("From %s # On host %s # Inbound channel %s\n\n",
  130.            (sender->ad_type == AD_X400_TYPE) ?
  131.            sender->ad_r400adr : sender->ad_r822adr,
  132.            que->inbound && que -> inbound -> li_mta ?
  133.            que -> inbound -> li_mta : "(none)",
  134.            que->inbound && que -> inbound -> li_chan ?
  135.            que -> inbound->li_chan->ch_name : "(none)");
  136. }
  137.  
  138. static LIST_RCHAN *getnthchannel(chans,num)
  139. LIST_RCHAN      *chans;
  140. int             num;
  141. {
  142.     LIST_RCHAN      *ix = chans;
  143.     int             icount = 0;
  144.  
  145.     while ((ix != NULL) && (icount++ < num)) 
  146.         ix = ix->li_next;
  147.  
  148.     return ix;
  149. }
  150.  
  151. static RecipPrint(recip)
  152. ADDR    *recip;
  153. {
  154.     LIST_RCHAN      *ix;
  155.     printf("To %s #",
  156.            (recip->ad_type == AD_X400_TYPE) ? recip->ad_r400adr : recip->ad_r822adr);
  157.     if (recip->ad_outchan == NULL)
  158.         printf(" NO OUTBOUND CHANNEL # Status ");
  159.     else
  160.         printf(" On outbound channel %s # Status ",
  161.                recip->ad_outchan->li_chan->ch_name);
  162.  
  163.     switch(recip->ad_status) {
  164.         case AD_STAT_PEND:
  165.         printf("pending\n");
  166.         break;
  167.         case AD_STAT_DRREQUIRED:
  168.         printf("delivery notification required\n");
  169.         break;
  170.         case AD_STAT_DRWRITTEN:
  171.         printf("delivery notification written\n");
  172.         break;
  173.         case AD_STAT_DONE:
  174.         printf("done\n");
  175.         return;
  176.         case AD_STAT_UNKNOWN:
  177.         default:
  178.         printf("unknown\n");
  179.         break;
  180.     }
  181.  
  182.     if ((ix = getnthchannel(recip->ad_fmtchan,recip->ad_rcnt)) != NULL) {
  183.         printf("Reformating channels left = ");
  184.         while (ix != NULL) {
  185.             printf(" %s ->  ",ix->li_chan->ch_name);
  186.             ix = ix->li_next;
  187.         }
  188.     printf("\n");
  189.     }
  190. }
  191.